package com.hx.jvm.classloader.loader;


import java.lang.reflect.Method;

/**
 * @author jxlgcmh
 * @date 2020-08-02 14:30
 * @description 测试自定义的的类来加载类
 */
public class MainApplication {
    public static void main(String[] args) throws Exception {
        // class文件的路径
        String classPath = "D:\\Code\\git\\learn-java\\out\\production\\learn-java\\com\\hx\\base\\Demo1.class";
        MyClassLoader myClassLoader = new MyClassLoader(classPath);
        // 全类名
        String allNamePath = "com.hx.base.Demo1";

        Class<?> clazz = myClassLoader.findClass(allNamePath);

        System.out.println("clazz的类加载器是" + clazz.getClassLoader());

        Method method = clazz.getDeclaredMethod("main", String[].class);

        Object instance = clazz.newInstance();
        // 执行这个方法
        method.invoke(instance, (Object) new String[]{});
    }
}
